package com.example.demo.service;

import com.example.demo.mapper.BookMapper;
import com.example.demo.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Book;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @className: BookService
 * @author: 芃
 * @description:
 * @date: 2024/12/23 10:06
 */
@Service
public class BookService {

    @Autowired
    private BookMapper mapper;


    public List<BookInfo> getBookList(){
        List<BookInfo> bookInfoList = new ArrayList<BookInfo>();
        mockData(bookInfoList);
        for (int i = 0; i < bookInfoList.size(); i++) {
            if (bookInfoList.get(i).getStatus() == 1){
                bookInfoList.get(i).setStatusCN("可借阅");
            }else {
                bookInfoList.get(i).setStatusCN("不可借阅");
            }
        }
        return bookInfoList;
    }


    private void mockData(List<BookInfo> bookInfoList) {
        int status = 1;
        for (int i = 0; i < 10; i++) {
            BookInfo bookInfo = new BookInfo();
            bookInfo.setId(i);
            bookInfo.setBookName("图书"+i);
            bookInfo.setAuthor("作者"+i);
            bookInfo.setPrice(new Random().nextDouble()*100);
            bookInfo.setCount(new Random().nextInt(100));
            bookInfo.setPublish("出版社"+i);
            bookInfo.setStatus(status);
            status = -status;
            bookInfoList.add(bookInfo);
        }
    }
}
